from ogreEx.axis import AXIS_MODES
from ogreEx.blender.props import IntProperty, StringProperty, EnumProperty, BoolProperty, FloatProperty
from ogreEx.blender.types import Operator
from ogreEx.config import getConfig
from ogreEx.constants import _IMAGE_FORMATS
from ogreEx.ogre.C_OgreCommonExport_ import _OgreCommonExport_
from ogreEx.ui.UIClass import MINI

@MINI
class INFO_OT_createRealxtendExport(Operator, _OgreCommonExport_):

    '''Export RealXtend Scene'''

    bl_idname  = "ogre.export_realxtend"
    bl_label   = "Export RealXtend"
    bl_options = {'REGISTER', 'UNDO'}

    EX_SWAP_AXIS             = EnumProperty   (name='swap axis'                 ,default=getConfig()['SWAP_AXIS'            ],items=AXIS_MODES ,description='axis swapping mode')
    # Basic options
    EX_SEP_MATS              = BoolProperty   (name="Separate Materials"        ,default=getConfig()['SEP_MATS'             ]                  ,description="exports a .material for each material (rather than putting all materials in a single .material file)")
    EX_ONLY_DEFORMABLE_BONES = BoolProperty   (name="Only Deformable Bones"     ,default=getConfig()['ONLY_DEFORMABLE_BONES']                  ,description="only exports bones that are deformable. Useful for hiding IK-Bones used in Blender. Warning: Will cause trouble if a deformable bone has a non-deformable parent")
    EX_ONLY_ANIMATED_BONES   = BoolProperty   (name="Only Animated Bones"       ,default=getConfig()['ONLY_ANIMATED_BONES'  ]                  ,description="only exports bones that have been keyframed, useful for run-time animation blending (example: upper/lower torso split)")

    EX_SCENE                 = BoolProperty   (name="Export Scene"              ,default=getConfig()['SCENE'                ]                  ,description="export current scene (OgreDotScene xml)"                 )
    EX_SELONLY               = BoolProperty   (name="Export Selected Only"      ,default=getConfig()['SELONLY'              ]                  ,description="export selected"                                         )
    EX_FORCE_CAMERA          = BoolProperty   (name="Force Camera"              ,default=getConfig()['FORCE_CAMERA'         ]                  ,description="export active camera"                                    )
    EX_FORCE_LAMPS           = BoolProperty   (name="Force Lamps"               ,default=getConfig()['FORCE_LAMPS'          ]                  ,description="export all lamps"                                        )
    EX_MESH                  = BoolProperty   (name="Export Meshes"             ,default=getConfig()['MESH'                 ]                  ,description="export meshes"                                           )
    EX_MESH_OVERWRITE        = BoolProperty   (name="Export Meshes (overwrite)" ,default=getConfig()['MESH_OVERWRITE'       ]                  ,description="export meshes (overwrite existing files)"                )
    EX_ARM_ANIM              = BoolProperty   (name="Armature Animation"        ,default=getConfig()['ARM_ANIM'             ]                  ,description="export armature animations - updates the .skeleton file" )
    EX_SHAPE_ANIM            = BoolProperty   (name="Shape Animation"           ,default=getConfig()['SHAPE_ANIM'           ]                  ,description="export shape animations - updates the .mesh file"        )
    EX_INDEPENDENT_ANIM      = BoolProperty   (name="Independent Animations"    ,default=getConfig()['INDEPENDENT_ANIM'     ]                  ,description="Export each NLA-Strip independently. If unchecked NLA-Strips that overlap influence each other.")
    EX_TRIM_BONE_WEIGHTS     = FloatProperty  (name="Trim Weights"              ,default=getConfig()['TRIM_BONE_WEIGHTS'    ],min=0.0, max=0.5 ,description="ignore bone weights below this value (Ogre supports 4 bones per vertex)")

    EX_ARRAY                 = BoolProperty   (name="Optimize Arrays"           ,default=getConfig()['ARRAY'                ]                       ,description="optimize array modifiers as instances (constant offset only)")
    EX_MATERIALS             = BoolProperty   (name="Export Materials"          ,default=getConfig()['MATERIALS'            ]                       ,description="exports .material script"                                    )
    EX_FORCE_IMAGE_FORMAT    = EnumProperty   (name='Convert Images'            ,default=getConfig()['FORCE_IMAGE_FORMAT'   ] ,items=_IMAGE_FORMATS ,description='convert all textures to format'                              )
    EX_DDS_MIPS              = IntProperty    (name="DDS Mips"                  ,default=getConfig()['DDS_MIPS'             ] ,min=0, max=16        ,description="number of mip maps (DDS)"                                    )

    # Mesh options
    EX_lodLevels             = IntProperty    (name="LOD Levels"                ,default=getConfig()['lodLevels'            ] ,min=0 ,max=    32 ,description="MESH number of LOD levels"                      )
    EX_lodDistance           = IntProperty    (name="LOD Distance"              ,default=getConfig()['lodDistance'          ] ,min=0 ,max=  2000 ,description="MESH distance increment to reduce LOD"          )
    EX_lodPercent            = IntProperty    (name="LOD Percentage"            ,default=getConfig()['lodPercent'           ] ,min=0 ,max=    99 ,description="LOD percentage reduction"                       )
    EX_nuextremityPoints     = IntProperty    (name="Extremity Points"          ,default=getConfig()['nuextremityPoints'    ] ,min=0 ,max= 65536 ,description="MESH Extremity Points"                          )
    EX_generateEdgeLists     = BoolProperty   (name="Edge Lists"                ,default=getConfig()['generateEdgeLists'    ]                    ,description="MESH generate edge lists (for stencil shadows)" )
    EX_generateTangents      = BoolProperty   (name="Tangents"                  ,default=getConfig()['generateTangents'     ]                    ,description="MESH generate tangents"                         )
    EX_tangentSemantic       = StringProperty (name="Tangent Semantic"          ,default=getConfig()['tangentSemantic'      ] ,maxlen=3          ,description="MESH tangent semantic"                          )
    EX_tangentUseParity      = IntProperty    (name="Tangent Parity"            ,default=getConfig()['tangentUseParity'     ] ,min=0 ,max=    16 ,description="MESH tangent use parity"                        )
    EX_tangentSplitMirrored  = BoolProperty   (name="Tangent Split Mirrored"    ,default=getConfig()['tangentSplitMirrored' ]                    ,description="MESH split mirrored tangents"                   )
    EX_tangentSplitRotated   = BoolProperty   (name="Tangent Split Rotated"     ,default=getConfig()['tangentSplitRotated'  ]                    ,description="MESH split rotated tangents"                    )
    EX_reorganiseBuffers     = BoolProperty   (name="Reorganise Buffers"        ,default=getConfig()['reorganiseBuffers'    ]                    ,description="MESH reorganise vertex buffers"                 )
    EX_optimiseAnimations    = BoolProperty   (name="Optimize Animations"       ,default=getConfig()['optimiseAnimations'   ]                    ,description="MESH optimize animations"                       )

    filepath                 = StringProperty (name="File Path", default="", maxlen=1024, subtype='FILE_PATH', description="Filepath used for exporting .txml file")
    EXPORT_TYPE = 'REX'